package leetcode.offer;

import entity.ListNode;
import org.junit.Test;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/11/11
 */
public class offer05 {


    /**
     * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
     * <p>
     *  
     * <p>
     * 示例 1：
     * <p>
     * 输入：s = "We are happy."
     * 输出："We%20are%20happy."
     */

    @Test
    public void test() {
        String str = "We are happy.";
        System.out.println(replaceSpace(str));
    }

    public String replaceSpace(String s) {
        StringBuilder str = new StringBuilder();
        for (char c : s.toCharArray()) {
            if (c == ' ') {
                str.append("%20");
            } else {
                str.append(c);
            }
        }
        return str.toString();
    }

}
